package com.jinxin.platform.cdsmsmgr.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdsmsmgr.pojo.domains.SysUserVO;
import com.jinxin.platform.cdsmsmgr.pojo.entity.Constant;
import com.jinxin.platform.cdsmsmgr.pojo.entity.ResultEntity;
import com.jinxin.platform.cdsmsmgr.rpc.SysUserRpc;
import com.jinxin.platform.cdsmsmgr.service.ISendRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2020-07-03
 * @Author: Lingnan
 **/
@APCOSApi(value = "短信发送记录接口", developers = {"那个男人"}, description = "短信发送记录接口")
@RestController
@RequestMapping("/cdsmsmgr/smsSendRecord")
@Slf4j
public class SmsSendRecordController {
    @Autowired
    private ISendRecordService recordService;
    @Autowired
    private SysUserRpc sysUserRpc;

    @APCOSApiOperation(value = "分页获取短信发送记录", developers = {"lingnan"}, description = "分页获取短信发送记录",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_WEB)
    @GetMapping("/list")
    public Map<String,Object> list(@RequestParam long page, @RequestParam long limit,
                                   @RequestParam(name = "userName",required = false)String userName,
                                   @RequestParam(name = "phone",required = false)String phone,
                                   @RequestParam(name = "accountType") Integer accountType,
                                   @RequestParam(required = false,name = "startDate")String startDate,
                                   @RequestParam(required = false,name = "endDate")String endDate){
        SysUserVO currentUser = sysUserRpc.getCurrentUser();
        if (currentUser == null) {
            log.error("未登录--,smsSendRecord list接口");
            return null;
        }
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("userName", userName);
        param.put("phoneNumber", phone);
        String userAccount = currentUser.getUserAccount();
        if(!Constant.ACCOUNT_ADMIN.equals(userAccount)){
            param.put("operateUser", userAccount);
        }
        param.put("operateUser", Constant.ACCOUNT_ADMIN);
        param.put("accountType", accountType);
        param.put("startDate", startDate);
        param.put("endDate", endDate);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg","");
        resultMap.put("count", recordService.listPageCount(param));
        resultMap.put("data", recordService.listPage(param));
        return resultMap;
    }

    @APCOSApiOperation(value = "删除短信发送记录", developers = {"lingnan"}, description = "删除短信发送记录",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_WEB)
    @GetMapping("/deleteById")
    public ResultEntity deleteById(String id) {
        return recordService.deleteById(id);
    }

    @APCOSApiOperation(value = "批量删除发送记录", developers = {"lingnan"}, description = "批量删除发送记录",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/batchDelete")
    public JsonResult batchDelete(@RequestBody String[] idArr){
        return recordService.batchDelete(idArr);
    }
}
